package other.system.client.oa;

import com.rkhd.platform.sdk.exception.ScriptBusinessException;
import com.rkhd.platform.sdk.log.Logger;
import com.rkhd.platform.sdk.log.LoggerFactory;
import com.rkhd.platform.sdk.model.XObject;
import com.rkhd.platform.sdk.trigger.DataResult;
import com.rkhd.platform.sdk.trigger.Trigger;
import com.rkhd.platform.sdk.trigger.TriggerRequest;
import com.rkhd.platform.sdk.trigger.TriggerResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 审批模块数据新增前: 清空OA审批相关数据(主要针对复制功能)
 * @Author 黎炎松
 * 2024-07-08 16:27
 */
public class ClearApprovalData implements Trigger {
    private static final Logger logger = LoggerFactory.getLogger();
    private static String LOGGER_MSG = "审批模块数据新增前: 清空OA审批相关数据 ==> ";

    @Override
    public TriggerResponse execute(TriggerRequest request) throws ScriptBusinessException {
        logger.debug(LOGGER_MSG + " 触发开始 ");
        List<XObject> dataList = request.getDataList();
        List<DataResult> dataResultList = new ArrayList<>();
        for (XObject xObject : dataList) {
            xObject.setAttribute("oaApprovalLog__c", null); // 审批日志
            xObject.setAttribute("oaApprovalStatus__c", null); // 审批状态
            xObject.setAttribute("oaApprovalId__c", null); // OA审批数据id
            xObject.setAttribute("oaApprovalFile__c", null); // OA审批附件
            dataResultList.add(new DataResult(true, "", xObject));
        }
        return new TriggerResponse(true, "处理完成", dataResultList);
    }


}
